package com.dou.you.che.service.impl.sys;

import com.dou.you.che.comm.utils.IdUtil;
import com.dou.you.che.core.mapper.sys.SysRoleMenuDao;
import com.dou.you.che.service.sys.SysRoleMenuServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 角色-菜单
 * @Author 黄国刚【1058118328@qq.com】
 */
@Service
@Transactional(readOnly = true)
public class SysRoleMenuService implements SysRoleMenuServiceI{

    @Autowired
    private SysRoleMenuDao sysRoleMenuDao;

    @Override
    @Transactional(readOnly = false)
    public void saveOrUpdate(String roleId, List<String> menuIdList) {
        if (menuIdList.size() == 0) {
            return;
        }
        //先删除角色与菜单关系
        sysRoleMenuDao.delete(roleId);

        //保存角色与菜单关系
        Map<String, Object> map = new HashMap<>();
        map.put("id", IdUtil.createIdbyUUID());
        map.put("roleId", roleId);
        map.put("menuIdList", menuIdList);
        sysRoleMenuDao.save(map);
    }

    @Override
    public List<String> queryMenuIdList(String roleId) {
        return sysRoleMenuDao.queryMenuIdList(roleId);
    }

}
